package com.lineage.data.event;

import com.lineage.data.executor.EventExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_HPUpdate;
import com.lineage.server.serverpackets.S_MPUpdate;
import com.lineage.server.serverpackets.S_OwnCharStatus;
import com.lineage.server.serverpackets.S_SPMR;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Event;
import java.util.Iterator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CardSet extends EventExecutor {
  private static final Log _log = LogFactory.getLog(CardSet.class);
  
  public static boolean START = false;
  
  public static int USE_TIME;
  
  public static int USE_TIME2;
  
  public static int USE_TIME3;
  
  public static EventExecutor get() {
    return new CardSet();
  }
  
  public void execute(L1Event event) {
    try {
      START = true;
      String[] set = event.get_eventother().split(",");
      try {
        USE_TIME = Integer.parseInt(set[0]);
      } catch (Exception e2) {
        USE_TIME = 720;
        _log.error("未设定月卡使用期限(使用预设720小时)");
      } 
      try {
        USE_TIME2 = Integer.parseInt(set[1]);
      } catch (Exception e2) {
        USE_TIME2 = 24;
        _log.error("未设定日卡使用期限(使用预设24小时)");
      } 
      try {
        USE_TIME3 = Integer.parseInt(set[2]);
      } catch (Exception e2) {
        USE_TIME3 = 1;
        _log.error("未设定日卡使用期限(使用预设1小时)");
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public static void load_card_mode(L1PcInstance pc) {
    try {
      Iterator<L1ItemInstance> iterator = pc.getInventory().getItems().iterator();
      while (iterator.hasNext()) {
        L1ItemInstance item = iterator.next();
        String classname = item.getItem().getclassname();
        if (classname.startsWith("shop.VIP_Card_")) {
          if (item.get_card_use() != 1) {
            item.setEquipped(false);
            continue;
          } 
          int card_id = 0;
          try {
            String cardmode = classname.substring(14);
            card_id = Integer.parseInt(cardmode);
          } catch (Exception e2) {
            String cardmode2 = classname.substring(15);
            card_id = Integer.parseInt(cardmode2);
          } 
          if (card_id == 0)
            return; 
          item.setEquipped(true);
          switch (card_id) {
            case 1:
              pc.set_VIP1(true);
              pc.addDmgup(3);
              pc.addHitup(2);
              pc.addBowDmgup(3);
              pc.addBowHitup(2);
              pc.addSp(2);
              pc.addMaxHp(200);
              pc.addMaxMp(100);
              pc.setCurrentHp(pc.getCurrentHp() + 200);
              pc.setCurrentMp(pc.getCurrentMp() + 100);
              pc.addStr(1);
              pc.addDex(1);
              pc.addCon(1);
              pc.addWis(1);
              pc.addInt(1);
              pc.addCha(1);
              pc.addRegistStun(3);
              pc.add_regist_freeze(3);
              pc.addRegistStone(3);
              pc.addRegistSleep(3);
              pc.addRegistSustain(3);
              pc.addRegistBlind(3);
              break;
            case 2:
              pc.set_VIP2(true);
              pc.add_exp(50);
              pc.addHpr(10);
              pc.addMpr(5);
              pc.addStr(1);
              pc.addDex(1);
              pc.addCon(1);
              pc.addWis(1);
              pc.addInt(1);
              pc.addCha(1);
              break;
            case 3:
              pc.set_VIP3(true);
              pc.add_exp(30);
              pc.addStr(2);
              pc.addDex(2);
              pc.addCon(2);
              pc.addWis(2);
              pc.addInt(2);
              pc.addCha(2);
              break;
            case 4:
              pc.add_exp(100);
              break;
            case 5:
              pc.add_exp(100);
              break;
          } 
          pc.sendPackets((ServerBasePacket)new S_OwnCharStatus(pc));
          pc.sendPackets((ServerBasePacket)new S_HPUpdate(pc.getCurrentHp(), pc.getMaxHp()));
          pc.sendPackets((ServerBasePacket)new S_MPUpdate(pc.getCurrentMp(), pc.getMaxMp()));
          pc.sendPackets((ServerBasePacket)new S_SPMR(pc));
        } 
      } 
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public static void set_card_mode(L1PcInstance pc, L1ItemInstance item) {
    if (!START)
      return; 
    try {
      String classname = item.getItem().getclassname();
      if (!classname.startsWith("shop.VIP_Card_"))
        return; 
      int card_id = 0;
      try {
        String cardmode = classname.substring(14);
        card_id = Integer.parseInt(cardmode);
      } catch (Exception e2) {
        String cardmode2 = classname.substring(15);
        card_id = Integer.parseInt(cardmode2);
      } 
      if (card_id == 0)
        return; 
      item.setEquipped(true);
      switch (card_id) {
        case 1:
          pc.set_VIP1(true);
          pc.addDmgup(3);
          pc.addHitup(2);
          pc.addBowDmgup(3);
          pc.addBowHitup(2);
          pc.addSp(2);
          pc.addMaxHp(200);
          pc.addMaxMp(100);
          pc.addStr(1);
          pc.addDex(1);
          pc.addCon(1);
          pc.addWis(1);
          pc.addInt(1);
          pc.addCha(1);
          pc.addRegistStun(3);
          pc.add_regist_freeze(3);
          pc.addRegistStone(3);
          pc.addRegistSleep(3);
          pc.addRegistSustain(3);
          pc.addRegistBlind(3);
          break;
        case 2:
          pc.set_VIP2(true);
          pc.add_exp(50);
          pc.addHpr(10);
          pc.addMpr(5);
          pc.addStr(1);
          pc.addDex(1);
          pc.addCon(1);
          pc.addWis(1);
          pc.addInt(1);
          pc.addCha(1);
          break;
        case 3:
          pc.set_VIP3(true);
          pc.add_exp(30);
          pc.addStr(2);
          pc.addDex(2);
          pc.addCon(2);
          pc.addWis(2);
          pc.addInt(2);
          pc.addCha(2);
          break;
        case 4:
          pc.add_exp(100);
          break;
        case 5:
          pc.add_exp(100);
          break;
      } 
      pc.sendPackets((ServerBasePacket)new S_OwnCharStatus(pc));
      pc.sendPackets((ServerBasePacket)new S_HPUpdate(pc.getCurrentHp(), pc.getMaxHp()));
      pc.sendPackets((ServerBasePacket)new S_MPUpdate(pc.getCurrentMp(), pc.getMaxMp()));
      pc.sendPackets((ServerBasePacket)new S_SPMR(pc));
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
  
  public static void remove_card_mode(L1PcInstance pc, L1ItemInstance item) {
    if (!START)
      return; 
    try {
      String classname = item.getItem().getclassname();
      if (!classname.startsWith("shop.VIP_Card_"))
        return; 
      int card_id = 0;
      try {
        String cardmode = classname.substring(14);
        card_id = Integer.parseInt(cardmode);
      } catch (Exception e2) {
        String cardmode2 = classname.substring(15);
        card_id = Integer.parseInt(cardmode2);
      } 
      if (card_id == 0)
        return; 
      item.setEquipped(false);
      switch (card_id) {
        case 1:
          pc.set_VIP1(false);
          pc.addDmgup(-3);
          pc.addHitup(-2);
          pc.addBowDmgup(-3);
          pc.addBowHitup(-2);
          pc.addSp(-2);
          pc.addMaxHp(-200);
          pc.addMaxMp(-100);
          pc.addStr(-1);
          pc.addDex(-1);
          pc.addCon(-1);
          pc.addWis(-1);
          pc.addInt(-1);
          pc.addCha(-1);
          pc.addRegistStun(-3);
          pc.add_regist_freeze(-3);
          pc.addRegistStone(-3);
          pc.addRegistSleep(-3);
          pc.addRegistSustain(-3);
          pc.addRegistBlind(-3);
          break;
        case 2:
          pc.set_VIP2(false);
          pc.add_exp(-50);
          pc.addHpr(-10);
          pc.addMpr(-5);
          pc.addStr(-1);
          pc.addDex(-1);
          pc.addCon(-1);
          pc.addWis(-1);
          pc.addInt(-1);
          pc.addCha(-1);
          break;
        case 3:
          pc.set_VIP3(false);
          pc.add_exp(-30);
          pc.addStr(-2);
          pc.addDex(-2);
          pc.addCon(-2);
          pc.addWis(-2);
          pc.addInt(-2);
          pc.addCha(-2);
          break;
        case 4:
          pc.add_exp(-100);
          break;
        case 5:
          pc.add_exp(-100);
          break;
      } 
      pc.sendPackets((ServerBasePacket)new S_OwnCharStatus(pc));
      pc.sendPackets((ServerBasePacket)new S_SPMR(pc));
    } catch (Exception e) {
      _log.error(e.getLocalizedMessage(), e);
    } 
  }
}
